package com.whk.mapper;

import com.whk.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * 操作数据库员工表的接口
 */
@Mapper
public interface EmpMapper {

//    /**
//     * 查询员工总记录数
//     */
//    @Select("select count(*) from emp")
//    public  Integer count();

//    /**
//     * 查询员工信息
//     */
//    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp limit #{start}, #{pageSize}")
//    public  List<Emp> empList(Integer start, Integer pageSize);
//}
    /**
     * 查询员工信息(pagehelpper)
     */
//    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp")
    public  List<Emp> empList(String name, Short gender, LocalDate begin, LocalDate end);

    /**
     * 根据id删除员工信息
     */
    void delete(List<Integer> ids);

    /**
     * 新增员工信息
     * @param emp
     */
    @Select("insert into emp(username, name, gender, image,job, entrydate, dept_id, create_time, update_time) " +
            "VALUE (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime}, #{updateTime})")
    void insert(Emp emp);

    /**
     * 新增员工信息
     * @param emp
     */
    void update(Emp emp);

    /**
     * 根据id查询员工信息
     * @param id
     */
    @Select("select id, username, password, name, " +
            "gender, image, job, entrydate, dept_id, create_time, update_time from emp where id = #{id}")
    Emp selectById(Integer id);

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getByUsernameAndPassword(Emp emp);

    /**
     * 根据部门id删除员工
     * @param
     */
    @Delete("delete from emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);
}
